home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / pmdev / e / demos / menuverify.e < prev    next >
Encoding:
Text File  |  2000-02-28  |  6.3 KB  |  170 lines

  1. /* -- ----------------------------------------------------------------- -- *
  2.  * -- Program.....: MenuVerify.e                                        -- *
  3.  * -- Author......: Daniel Kasmeroglu <raptor@cs.tu-berlin.de>          -- *
  4.  * -- Description.: Port of an example by Henrik Isaksson.              -- *
  5.  * -- ----------------------------------------------------------------- -- *
  6.  * -- Original header:                                                  -- *
  7.  * --                                                                   -- *
  8.  * --   $VER: MenuVerify.c 1.1 (05.09.98)                               -- *
  9.  * --                                                                   -- *
  10.  * --   Popup Menu example program                                      -- *
  11.  * --                                                                   -- *
  12.  * --   ©1996-1997 Henrik Isaksson                                      -- *
  13.  * --   All Rights Reserved.                                            -- *
  14.  * --                                                                   -- *
  15.  * --   Run and click the mouse in the window!                          -- *
  16.  * --                                                                   -- *
  17.  * -- ----------------------------------------------------------------- -- */
  18.  
  19. /* -- ----------------------------------------------------------------- -- *
  20.  * --                              Options                              -- *
  21.  * -- ----------------------------------------------------------------- -- */
  22.  
  23. OPT PREPROCESS       -> enable preprocessor
  24.  
  25.  
  26. /* -- ----------------------------------------------------------------- -- *
  27.  * --                              Modules                              -- *
  28.  * -- ----------------------------------------------------------------- -- */
  29.  
  30. MODULE 'libraries/popupmenu'  ,
  31.        'intuition/intuition'  ,
  32.        'utility/tagitem'      
  33.  
  34. MODULE 'popupmenu'
  35.  
  36.  
  37. /* -- ----------------------------------------------------------------- -- *
  38.  * --                               Main                                -- *
  39.  * -- ----------------------------------------------------------------- -- */
  40.  
  41. ->»» PROC main
  42. PROC main()
  43. DEF ma_window : PTR TO window
  44. DEF ma_pmenu  : PTR TO popupmenu
  45. DEF ma_text1  : PTR TO intuitext
  46. DEF ma_text2  : PTR TO intuitext
  47. DEF ma_item1  : PTR TO menuitem
  48. DEF ma_item2  : PTR TO menuitem
  49. DEF ma_imenu  : PTR TO menu
  50. DEF ma_imsg1  : PTR TO intuimessage
  51. DEF ma_imsg2  : intuimessage
  52. DEF ma_result,ma_menu
  53.  
  54.   ma_result := TRUE
  55.   ma_menu   := FALSE
  56.  
  57.   -> Just a badly coded intuition menu....
  58.   ma_text1  := [ 2, 1, 1, 1, 1, 0, 'First Item' , NIL ]:intuitext
  59.   ma_text2  := [ 2, 1, 1, 1, 1, 0, 'Last Item'  , NIL ]:intuitext
  60.  
  61.   ma_item1  := [ NIL      , 0, 15 , 100, 10, ITEMENABLED OR ITEMTEXT OR HIGHCOMP, 0, ma_text2, NIL, 0, NIL, 0 ]:menuitem
  62.   ma_item2  := [ ma_item1 , 0, 0  , 100, 10, ITEMENABLED OR ITEMTEXT OR HIGHCOMP, 0, ma_text1, NIL, 0, NIL, 0 ]:menuitem
  63.  
  64.   ma_imenu  := [ NIL, 0, 0, 100, 12, MENUENABLED, 'Project', ma_item2, 0, 0, 0, 0 ]:menu
  65.  
  66.   popupmenubase := OpenLibrary( 'popupmenu.library', 9 )
  67.   IF popupmenubase <> NIL
  68.  
  69.     -> Create a very simple menu...
  70.     ma_pmenu := PMMenu( 'Inside the window !' ),
  71.                   PMItem( 'This example shows'  ), PM_NOSELECT, TRUE, PMEnd,
  72.                   PMItem( 'how to use popup'    ), PM_NOSELECT, TRUE, PMEnd,
  73.                   PMItem( 'menus and intuition' ), PM_NOSELECT, TRUE, PMEnd,
  74.                   PMItem( 'menus in the same'   ), PM_NOSELECT, TRUE, PMEnd,
  75.                   PMItem( 'window!'             ), PM_NOSELECT, TRUE, PMEnd,
  76.                   PMBar, PMEnd,
  77.                   PMItem( 'Quit' ), PM_USERDATA, 5, PMEnd,
  78.                 PMEnd
  79.  
  80.     IF ma_pmenu <> NIL
  81.  
  82.       ma_window := OpenWindowTagList( NIL,
  83.       [ WA_IDCMP       , IDCMP_CLOSEWINDOW OR IDCMP_MOUSEBUTTONS OR IDCMP_MENUVERIFY ,
  84.         WA_DRAGBAR     , TRUE              ,
  85.         WA_WIDTH       , 150               ,
  86.         WA_HEIGHT      , 100               ,
  87.         WA_LEFT        , 150               ,
  88.         WA_TOP         , 0                 ,
  89.         WA_TITLE       , 'MenuVerify Demo' ,
  90.         WA_CLOSEGADGET , TRUE              ,
  91.         TAG_END ] )
  92.  
  93.       IF ma_window <> NIL
  94.  
  95.         SetMenuStrip( ma_window, ma_imenu )
  96.  
  97.         WHILE ma_result <> FALSE
  98.  
  99.           -> Wait for a message
  100.           WaitPort( ma_window.userport )
  101.  
  102.           -> Get the message
  103.           WHILE (ma_imsg1 := GetMsg( ma_window.userport )) <> NIL
  104.  
  105.             -> Copy the contents of it
  106.             CopyMem( ma_imsg1, ma_imsg2, SIZEOF intuimessage )
  107.  
  108.             -> Check if the user wants to see the menu
  109.             IF ma_imsg1.class = IDCMP_MENUVERIFY
  110.  
  111.               -> Check if the mouse in our window
  112.               IF (ma_imsg1.mousey > 0) AND (ma_imsg1.mousey < ma_window.height) AND
  113.                  (ma_imsg1.mousex > 0) AND (ma_imsg1.mousex < ma_window.width)
  114.                                                            
  115.                 -> Cancel the intuition menu
  116.                 ma_imsg1.code  := MENUCANCEL
  117.                 -> Make sure the menu gets opened...
  118.                 ma_imsg1.class := IDCMP_MOUSEBUTTONS
  119.                 -> (we fake a IDCMP_MOUSEBUTTONS message)
  120.                 ma_imsg1.code  := MENUDOWN
  121.  
  122.               ENDIF
  123.  
  124.             ENDIF
  125.  
  126.             -> Reply the message
  127.             ReplyMsg( ma_imsg1 )
  128.  
  129.             IF ma_imsg1.class = IDCMP_CLOSEWINDOW
  130.               ma_result := FALSE
  131.             ELSEIF ma_imsg1.class = IDCMP_MOUSEBUTTONS
  132.  
  133.                -> Open only if the right (that is the
  134.                -> right button, in this case :) ) button was hit
  135.                IF (ma_imsg1.code = MENUUP) OR (ma_imsg1.code = MENUDOWN)
  136.  
  137.                   ma_result := Pm_OpenPopupMenuA( ma_window,
  138.                   [ PM_MENU, ma_pmenu      ,
  139.                     PM_CODE, ma_imsg1.code ,  -> This will ensure that the user can change
  140.                     TAG_END ] ) - 5           -> the time of apperance for the menu.
  141.  
  142.                ENDIF
  143.  
  144.             ENDIF
  145.  
  146.           ENDWHILE
  147.  
  148.         ENDWHILE
  149.  
  150.         ClearMenuStrip( ma_window )
  151.         CloseWindow( ma_window )
  152.  
  153.       ELSE
  154.         PrintF( 'Window error !\n' )
  155.       ENDIF
  156.  
  157.       Pm_FreePopupMenu( ma_pmenu )
  158.  
  159.     ELSE
  160.       PrintF( 'Menu error !\n' )
  161.     ENDIF
  162.     CloseLibrary( popupmenubase )
  163.  
  164.   ELSE
  165.     PrintF( 'Cannot open "popupmenu.library" v9+ !\n' )
  166.   ENDIF
  167.  
  168. ENDPROC
  169. ->»»>
  170.